package org.boz.dial;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ScrollView;


public class DialMain extends Activity {
	private LispInterpreter m_interpreter;
	
	public DialMain() {
		m_interpreter = new LispInterpreter();
	}
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        m_interpreter.addSymbol("activity", this);
        
        final TextView textView = (TextView) findViewById(R.id.textview);
        final EditText editText = (EditText) findViewById(R.id.edittext);
        final ScrollView scrollView = (ScrollView) findViewById(R.id.scrollview);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	String input = editText.getText().toString();
            	textView.append(input + "\n");
            	try {
            		LispObject result = m_interpreter.parseEval(input);
            		textView.append("=> " + result.toString() + "\n");
            	} catch (Throwable e) {
            		textView.append("=> error: " + e + "\n");
            	}
            	scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            	editText.setText("");
            }
        });
    }
}